package cn.iocoder.yudao.module.handguard.service.userbasetable4;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.handguard.controller.app.userbasetable4.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable4.UserBaseTable4DO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.handguard.convert.userbasetable4.UserBaseTable4Convert;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable4.UserBaseTable4Mapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.handguard.enums.ErrorCodeConstants.*;

/**
 * 工薪贷 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class UserBaseTable4ServiceImpl implements UserBaseTable4Service {

    @Resource
    private UserBaseTable4Mapper userBaseTable4Mapper;

    @Override
    public Long createUserBaseTable4(UserBaseTable4CreateReqVO createReqVO) {
        // 插入
        UserBaseTable4DO userBaseTable4 = UserBaseTable4Convert.INSTANCE.convert(createReqVO);
        userBaseTable4Mapper.insert(userBaseTable4);
        // 返回
        return userBaseTable4.getId();
    }

    @Override
    public void updateUserBaseTable4(UserBaseTable4UpdateReqVO updateReqVO) {
        // 校验存在
        validateUserBaseTable4Exists(updateReqVO.getId());
        // 更新
        UserBaseTable4DO updateObj = UserBaseTable4Convert.INSTANCE.convert(updateReqVO);
        userBaseTable4Mapper.updateById(updateObj);
    }

    @Override
    public void deleteUserBaseTable4(Long id) {
        // 校验存在
        validateUserBaseTable4Exists(id);
        // 删除
        userBaseTable4Mapper.deleteById(id);
    }

    private void validateUserBaseTable4Exists(Long id) {
        if (userBaseTable4Mapper.selectById(id) == null) {
            throw exception(USER_BASE_TABLE4_NOT_EXISTS);
        }
    }

    @Override
    public UserBaseTable4DO getUserBaseTable4(Long id) {
        LambdaQueryWrapper<UserBaseTable4DO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserBaseTable4DO::getApplicationId,id);
        return userBaseTable4Mapper.selectOne(queryWrapper);
    }

    @Override
    public List<UserBaseTable4DO> getUserBaseTable4List(Collection<Long> ids) {
        return userBaseTable4Mapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<UserBaseTable4DO> getUserBaseTable4Page(UserBaseTable4PageReqVO pageReqVO) {
        return userBaseTable4Mapper.selectPage(pageReqVO);
    }

    @Override
    public List<UserBaseTable4DO> getUserBaseTable4List(UserBaseTable4ExportReqVO exportReqVO) {
        return userBaseTable4Mapper.selectList(exportReqVO);
    }

}
